 
module flow_led(
  input sys_clk,
  input key1,
  input key2,
  output led,
  
  output [26:0] clk_outa,
  output [26:0] clk_outb,
  output [26:0] clk_outc,
  output [26:0] clk_outd,
  output [38:0] clk_oute,
   // TMDS outputs
   output         TMDS_CLK,
   output [2:0]   TMDS_DATA
 
);
assign clk_oute[0]   = sys_clk;
assign clk_oute[1]   = sys_clk;
assign clk_oute[2]   = sys_clk;
assign clk_oute[3]   = sys_clk;
assign clk_oute[4]   = sys_clk;
assign clk_oute[5]   = sys_clk;
assign clk_oute[6]   = sys_clk;
assign clk_oute[7]   = sys_clk;
assign clk_oute[8]   = sys_clk;
assign clk_oute[9]   = sys_clk;
assign clk_oute[10]  = sys_clk;
assign clk_oute[11]  = sys_clk;
assign clk_oute[12]  = sys_clk;
assign clk_oute[13]  = sys_clk;
assign clk_oute[14]  = sys_clk;
assign clk_oute[15]  = sys_clk;
assign clk_oute[16]  = sys_clk;
assign clk_oute[17]  = sys_clk;
assign clk_oute[18]  = sys_clk;
assign clk_oute[19]  = sys_clk;
assign clk_oute[20]  = sys_clk;
assign clk_oute[21]  = sys_clk;
assign clk_oute[22]  = sys_clk;
assign clk_oute[23]  = sys_clk;
assign clk_oute[24]  = sys_clk;
assign clk_oute[25]  = sys_clk;
assign clk_oute[26]  = sys_clk;
assign clk_oute[27]  = sys_clk;
assign clk_oute[28]  = sys_clk;
assign clk_oute[29]  = sys_clk;
assign clk_oute[30]  = sys_clk;
assign clk_oute[31]  = sys_clk;
assign clk_oute[32]  = sys_clk;
assign clk_oute[33]  = sys_clk;
assign clk_oute[34]  = sys_clk;
assign clk_oute[35]  = sys_clk;
assign clk_oute[36]  = sys_clk;
assign clk_oute[37]  = sys_clk;
assign clk_oute[38]  = sys_clk;

assign clk_outa[0]    = sys_clk;
assign clk_outa[1]    = sys_clk;
assign clk_outa[2]    = sys_clk;
assign clk_outa[3]    = sys_clk;
assign clk_outa[4]    = sys_clk;
assign clk_outa[5]    = sys_clk;
assign clk_outa[6]    = sys_clk;
assign clk_outa[7]    = sys_clk;
assign clk_outa[8]    = sys_clk;
assign clk_outa[9]    = sys_clk;
assign clk_outa[10]   = sys_clk;
assign clk_outa[11]   = sys_clk;
assign clk_outa[12]   = sys_clk;
assign clk_outa[13]   = sys_clk;
assign clk_outa[14]   = sys_clk;
assign clk_outa[15]   = sys_clk;
assign clk_outa[16]   = sys_clk;
assign clk_outa[17]   = sys_clk;
assign clk_outa[18]   = sys_clk;
assign clk_outa[19]   = sys_clk;
assign clk_outa[20]   = sys_clk;
assign clk_outa[21]   = sys_clk;
assign clk_outa[22]   = sys_clk;
assign clk_outa[23]   = sys_clk;
assign clk_outa[24]   = sys_clk;
assign clk_outa[25]   = sys_clk;
assign clk_outa[26]   = sys_clk;

assign clk_outb[0]   = sys_clk;
assign clk_outb[1]   = sys_clk;
assign clk_outb[2]   = sys_clk;
assign clk_outb[3]   = sys_clk;
assign clk_outb[4]   = sys_clk;
assign clk_outb[5]   = sys_clk;
assign clk_outb[6]   = sys_clk;
assign clk_outb[7]   = sys_clk;
assign clk_outb[8]   = sys_clk;
assign clk_outb[9]   = sys_clk;
assign clk_outb[10]  = sys_clk;
assign clk_outb[11]  = sys_clk;
assign clk_outb[12]  = sys_clk;
assign clk_outb[13]  = sys_clk;
assign clk_outb[14]  = sys_clk;
assign clk_outb[15]  = sys_clk;
assign clk_outb[16]  = sys_clk;
assign clk_outb[17]  = sys_clk;
assign clk_outb[18]  = sys_clk;
assign clk_outb[19]  = sys_clk;
assign clk_outb[20]  = sys_clk;
assign clk_outb[21]  = sys_clk;
assign clk_outb[22]  = sys_clk;
assign clk_outb[23]  = sys_clk;
assign clk_outb[24]  = sys_clk;
assign clk_outb[25]  = sys_clk;
assign clk_outb[26]  = sys_clk;

assign clk_outc[0]    = sys_clk;
assign clk_outc[1]    = sys_clk;
assign clk_outc[2]    = sys_clk;
assign clk_outc[3]    = sys_clk;
assign clk_outc[4]    = sys_clk;
assign clk_outc[5]    = sys_clk;
assign clk_outc[6]    = sys_clk;
assign clk_outc[7]    = sys_clk;
assign clk_outc[8]    = sys_clk;
assign clk_outc[9]    = sys_clk;
assign clk_outc[10]   = sys_clk;
assign clk_outc[11]   = sys_clk;
assign clk_outc[12]   = sys_clk;
assign clk_outc[13]   = sys_clk;
assign clk_outc[14]   = sys_clk;
assign clk_outc[15]   = sys_clk;
assign clk_outc[16]   = sys_clk;
assign clk_outc[17]   = sys_clk;
assign clk_outc[18]   = sys_clk;
assign clk_outc[19]   = sys_clk;
assign clk_outc[20]   = sys_clk;
assign clk_outc[21]   = sys_clk;
assign clk_outc[22]   = sys_clk;
assign clk_outc[23]   = sys_clk;
assign clk_outc[24]   = sys_clk;
assign clk_outc[25]   = sys_clk;
assign clk_outc[26]   = sys_clk;

assign clk_outd[0]      = sys_clk;
assign clk_outd[1]      = sys_clk;
assign clk_outd[2]      = sys_clk;
assign clk_outd[3]      = sys_clk;
assign clk_outd[4]      = sys_clk;
assign clk_outd[5]      = sys_clk;
assign clk_outd[6]      = sys_clk;
assign clk_outd[7]      = sys_clk;
assign clk_outd[8]      = sys_clk;
assign clk_outd[9]      = sys_clk;
assign clk_outd[10]     = sys_clk;
assign clk_outd[11]     = sys_clk;
assign clk_outd[12]     = sys_clk;
assign clk_outd[13]     = sys_clk;
assign clk_outd[14]     = sys_clk;
assign clk_outd[15]     = sys_clk;
assign clk_outd[16]     = sys_clk;
assign clk_outd[17]     = sys_clk;
assign clk_outd[18]     = sys_clk;
assign clk_outd[19]     = sys_clk;
assign clk_outd[20]     = sys_clk;
assign clk_outd[21]     = sys_clk;
assign clk_outd[22]     = sys_clk;
assign clk_outd[23]     = sys_clk;
assign clk_outd[24]     = sys_clk;
assign clk_outd[25]     = sys_clk;
assign clk_outd[26]     = sys_clk;

/*******************************************************************
Function for reversing the number of bits in a 10 bit parallel bus.
*******************************************************************/
function [10-1:0] bitOrder10 (input [10-1:0]  data);
integer i;
begin
   for (i=0; i < 10; i=i+1) begin : reverse
      bitOrder10[10-1-i] = data[i]; //Note how the vectors get swapped around here by the index. For i=0, i_out=15, and vice versa.
   end
end
endfunction

/*******************************************************************
Declare some internal wires.
*******************************************************************/
wire hsync, vsync, blank;
wire pixclk;
wire [9:0] TMDS_red, TMDS_green, TMDS_blue;
wire [23:0] vdata;

/*******************************************************************
R, G, B TMDS encoder instances
*******************************************************************/ 
TMDS_encoder encode_R(.clk(pixclk), .VD( vdata[23:16] ), .CD(2'b00), .VDE(blank), .TMDS(TMDS_red));
TMDS_encoder encode_G(.clk(pixclk), .VD( vdata[15:8] ), .CD(2'b00), .VDE(blank), .TMDS(TMDS_green));
TMDS_encoder encode_B(.clk(pixclk), .VD( vdata[7:0] ), .CD({vsync, hsync}), .VDE(blank), .TMDS(TMDS_blue));

/*******************************************************************
TMDS serializer of type ALTLVDS_TX
*******************************************************************/
serializer serializer_inst (
   .tx_in ( {bitOrder10(TMDS_red), bitOrder10(TMDS_green), bitOrder10(TMDS_blue), 10'b0011111000} ),
   .tx_inclock ( sys_clk ),
   .tx_coreclock ( pixclk  ),
   .tx_out ( {TMDS_DATA, TMDS_CLK} )
   );
   
wire  [10:0]  pixel_xpos_w;
wire  [10:0]  pixel_ypos_w;
wire  [23:0]  pixel_data_w;

video_driver u_video_driver(
    .pixel_clk      (pixclk),
    .sys_rst_n      (1),

    .video_hs       (hsync),
    .video_vs       (vsync),
    .video_de       (blank),
    .video_rgb      (vdata),

    .pixel_xpos     (pixel_xpos_w),
    .pixel_ypos     (pixel_ypos_w),
    .pixel_data     (pixel_data_w)
    );

video_display  u_video_display(
    .pixel_clk      (pixclk),
    .sys_rst_n      (1),

    .pixel_xpos     (pixel_xpos_w),
    .pixel_ypos     (pixel_ypos_w),
    .pixel_data     (pixel_data_w)
    );

endmodule
